package org.jadapter.examples.wiki;

import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.jadapter.Query.$;
import org.jadapter.registry.AdapterRegistry;
import org.jadapter.registry.TransientAdapterRegistry;
import org.jadapter.Query;

import java.util.Collection;
import java.util.Arrays;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: pjesi
 * Date: Apr 23, 2009
 * Time: 2:10:56 PM
 * To change this template use File | Settings | File Templates.
 */
public class CollectionExample {

    @Test
    public void collections_with_multiple_types() {

        Collection<?> collection = Arrays.asList("", new Date());

        AdapterRegistry registry = new TransientAdapterRegistry();
        registry.register(StringHandler.class);
        registry.register(DateHandler.class);

        for (Object object : collection) {
            Handler handler = registry.transform(object, Handler.class);
            handler.handle();
        }

        assertTrue(StringHandler.handled && DateHandler.handled);
    }

    @Test
    public void collections_with_multiple_types_using_query() {

        AdapterRegistry registry = new TransientAdapterRegistry();
        registry.register(StringHandler.class);
        registry.register(DateHandler.class);

        Collection<?> c = Arrays.asList("", new Date());

        $(c).map(registry, Handler.class).each().handle();



        assertTrue(StringHandler.handled && DateHandler.handled);
    }

}
